import axios from 'axios'

export default {
  namespaced: true,
  state: {
    token: localStorage.getItem('token') || '',
    userinfo: {

    }
  },
  getters: {
  },
  mutations: {
    setToken (state, token) {
      console.log(123)
      state.token = token
      localStorage.setItem('token', token)
    },
    updateUserinfo (state, val) {
      state.userinfo = val
    }
  },
  actions: {
    async getUserinfo (ctx) {
      // console.log(ctx)
      const { data: res } = await axios.get('/my/userinfo', { headers: { Authorization: ctx.state.token } })
      if (res.code !== 0) return
      ctx.commit('updateUserinfo', res.data)
    }
  }
}
